﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using University.Workshop.Model;
using University.Workshop.DataAccess;
using System.Windows.Forms;
using System.Collections.ObjectModel;

namespace University.Workshop.Business
{
    public static class BookingManager
    {
        // Habitaciones Libres por el tipo

        public static bool ValidDateCheckInCheckout(DateTime check, DateTime checkout)
        {
            if (checkout.Year > check.Year) { return true; }
            else
            {
                if (checkout.Year == check.Year)
                {
                    if (checkout.Month > check.Month) { return true; }
                    else
                    {
                        if (checkout.Month == check.Month)
                        {
                            return (checkout.Day >= check.Day);
                        }
                        else { return false; }
                    }
                }
                else { return false; }
            }
        }
        public static bool ValidDate(DateTime check, DateTime checkout)
        {
            //los anios puedes ser iguales
            //los meses pueden ser iguales pero no los dias
            DateTime today = DateTime.Today;

            if ((check != checkout) && (today < check) && (today < checkout))
            {
                return ValidDateCheckInCheckout(check, checkout);
            }
            else { return false; }

        }

        public static Collection<Room> SearchByTypeAndDate(Booking book)
        {
            BookingDataAccess bookingDal = new BookingDataAccess();
            bookingDal.Dispose();
            Collection<Room> avilablesRooms = bookingDal.SearchBooking(book);
            return avilablesRooms;
        }
        public static void GetAllRoomsAvailable(DataGridView rooms, Collection<Room> roomsList)
        {
            BookingDataAccess bookingdal = new BookingDataAccess();
            bookingdal.Dispose();
            bookingdal.GetAllRoomsDataGrid(rooms, roomsList);
        }
        public static bool BookARoom(Booking bookingRoom)
        {
            BookingDataAccess bookingdal = new BookingDataAccess();
            bookingdal.Dispose();
            return (bookingdal.BookARoom(bookingRoom));
        }
        public static bool SearchAllBookedRoomsByType(DataGridView rooms, int idTypeOfRoom)
        {
            BookingDataAccess bookingdal = new BookingDataAccess();
            bookingdal.Dispose();
            return (bookingdal.GetAllRoomsDataGridType(rooms, idTypeOfRoom));
        }

        public static bool SearchAllBookedRoomsByDate(DataGridView resultDataGridView, DateTime checkDate, DateTime checkoutDate)
        {
            BookingDataAccess bookingdal = new BookingDataAccess();
            bookingdal.Dispose();
            return (bookingdal.GetAllRoomsDataGridByDate(resultDataGridView, checkDate, checkoutDate));
        }

        public static bool DeleteBooking(Booking book)
        {
            BookingDataAccess bookingDal = new BookingDataAccess();
            bookingDal.Dispose();
            return (bookingDal.DeleteBooking(book));
        }

    }
}
